<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改家庭成员')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-family-edit" th:object="${basicFamily}">
            <input name="familyId" id="familyId" th:field="*{familyId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">员工姓名：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="houseId" type="hidden" th:field="*{userId}"  />
                        <input class="form-control" type="text" onclick="selectUserTree()" id="treeName" readonly="true" th:field="*{userName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <input name="familyName" id="familyName" th:field="*{familyName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">称谓：</label>
                <div class="col-sm-8">
                    <select name="familyTitle" class="form-control m-b" th:with="type=${@dict.getType('basic_user_family')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{familyTitle}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="familyMobile" id="familyMobile" th:field="*{familyMobile}" class="form-control" type="text" maxlength="11">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">工作单位：</label>
                <div class="col-sm-8">
                    <input name="familyAddress" th:field="*{familyAddress}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职务：</label>
                <div class="col-sm-8">
                    <input name="familyDuty" th:field="*{familyDuty}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">出生日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="familyBirthday" class="form-control" th:field="*{familyBirthday}" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">政治面貌：</label>
                <div class="col-sm-8">
                    <select name="familyPolitical" class="form-control m-b" th:with="type=${@dict.getType('basic_user_political')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{familyPolitical}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/family";
        $("#form-family-edit").validate({
            rules:{
                familyName:{
                    remote: {
                        url: prefix + "/checkFamilyNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "familyName": function() {
                                return $.common.trim($("#familyName").val());
                            },
                            "userId": function() {
                                return $("#treeId").val();
                            },
                            "familyId": function() {
                                return $("#familyId").val();
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                familyMobile:{
                    isPhone:true
                }
            },
            messages: {
                "familyName": {
                    remote: "家庭成员已经存在"
                }
            },
            focusCleanup: true
        });

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择员工',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var treeType = body.find('#treeType').val();
            if(treeType == 'user'){
                var id = body.find('#treeId').val();
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                $("#treeId").val(treeId);
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }else{
                $.modal.alertError("请选择员工");
            }
        }

        $("input[name='familyBirthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-family-edit').serialize());
            }
        }
    </script>
</body>
</html>